package com.myblog.mapper;

import com.myblog.model.Comment;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Mapper
public interface CommentMapper {

    @Select("select * from comment_record order by id desc ")
    List<Comment> selectAllCommentOrder();

    @Select("select count(*) from comment_record")
    Integer selectNumOfComment();

    @Select("select count(*) from comment_record where respondentId = #{respondentId} and isRead = 1")
    Integer selectNotReadNumByRespondentId(@Param(value = "respondentId") Integer userId);

    @Select("select * from comment_record where respondentId = #{respondentId} order by id desc ")
    List<Comment> selectCommentByRespondentId(@Param(value = "respondentId") Integer userId);

    @Update("update comment_record set isRead = 0 where respondentId = #{respondentId} and isRead = 1")
    void updateAllCommentIsReadByRespondentId(@Param(value = "respondentId") Integer respondentId);

    @Select("select * from comment_record where articleId = #{articleId} order by id desc")
    List<Comment> selectCommentByArticleId(@Param("articleId") long articleId);

    void addComment(Comment comment);

    @Update("update comment_record set likes = likes+1 where id = #{id}")
    void updateLikeById(@Param(value = "id")Integer commentId);

    @Select(("select likes from comment_record where id = #{id};"))
    int queryLikesById(@Param(value = "id")Integer commentId);
}
